package com.example.demo.config.mybatis.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.example.demo.config.druid.properties.DruidProperties;
import com.example.demo.config.mybatis.plugin.BaseDataPrivilegeInterceptor;
import com.example.demo.config.mybatis.plugin.ServiceInterceptor1;
import com.example.demo.config.mybatis.plugin.ServiceInterceptor2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author zhouhong mybatis配置文件
 * @create 2018/4/4
 * @modify
 */
@Configuration
@EnableTransactionManagement(order = 2)
@MapperScan(basePackages = {"com.example.demo.**.mappers"})
public class MybatisPlusConfig {
    @Autowired
    private DruidProperties druidProperties;

    /**
     * 配置数据源
     * @return
     */
    @Bean
    public DruidDataSource singleDatasource(){
        //初始化数据源
        DruidDataSource druidDataSource=new DruidDataSource();
        //配置数据源
        druidProperties.config(druidDataSource);
        return druidDataSource;
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    @Bean
    public BaseDataPrivilegeInterceptor baseDataPrivilegeInterceptor(){
        return new BaseDataPrivilegeInterceptor();
    }

    @Bean
    public ServiceInterceptor1 serviceInterceptor1(){
        return new ServiceInterceptor1();
    }
    @Bean
    public ServiceInterceptor2 serviceInterceptor2(){
        return new ServiceInterceptor2();
    }
}
